//
//  NetworkManager.m
//  QuickCare
//
//  Created by lidabiao on 16/7/11.
//  Copyright © 2016年 lidabiao. All rights reserved.
//

#import "NetworkManager.h"

@implementation NetworkManager

+(instancetype)shareManager{

    static NetworkManager *manager;
    
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^
    {
        manager = [[NetworkManager alloc] init];
        //需要json请求
        manager.requestSerializer = [AFJSONRequestSerializer serializer];
        //需要设置返回值类型修改
        manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript", @"text/html",nil];
    });
    return manager;
}

-(void)requestDataWithURLString:(NSString *)URLString parameters:(NSDictionary *)parameters success:(void(^)(id response))success failure:(void(^)(NSError *error))failure
{
    [[NetworkManager shareManager] POST:URLString parameters:parameters progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject)
     {
        success(responseObject);
    }
     failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error)
    {
        failure(error);
    }];
}

- (void)requestWeatherWithURLString:(NSString *)URLString parameters:(NSDictionary *)parameters success:(void (^)(id))success failure:(void (^)(NSError *))failure {
    [[NetworkManager shareManager] GET:URLString parameters:parameters progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        success(responseObject);
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        failure(error);
    }];
}

@end
